package com.qiangesoft.miniapp.properties;

import com.qiangesoft.miniapp.enums.HttpClientType;
import com.qiangesoft.miniapp.enums.StorageType;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 属性配置类
 *
 * @author qiangesoft
 * @since 2024-07-16
 */
@Data
@ConfigurationProperties(prefix = WxMaProperties.PREFIX)
public class WxMaProperties {

    public static final String PREFIX = "wx.miniapp";

    /**
     * 微信小程序的appid.
     */
    private String appid;

    /**
     * 微信小程序的Secret.
     */
    private String secret;

    /**
     * 微信小程序消息服务器配置的token.
     */
    private String token;

    /**
     * 微信小程序消息服务器配置的EncodingAESKey.
     */
    private String aesKey;

    /**
     * 消息格式，XML或者JSON.
     */
    private String msgDataFormat;

    /**
     * 存储策略
     */
    private final ConfigStorage configStorage = new ConfigStorage();

    /**
     * 存储配置类
     */
    @Data
    public static class ConfigStorage {

        /**
         * 存储类型.
         */
        private StorageType type = StorageType.Memory;

        /**
         * 指定key前缀.
         */
        private String keyPrefix = "wa";

        /**
         * http客户端类型.
         */
        private HttpClientType httpClientType = HttpClientType.HttpClient;

        /**
         * http代理主机.
         */
        private String httpProxyHost;

        /**
         * http代理端口.
         */
        private Integer httpProxyPort;

        /**
         * http代理用户名.
         */
        private String httpProxyUsername;

        /**
         * http代理密码.
         */
        private String httpProxyPassword;

        /**
         * http 请求重试间隔
         * <pre>
         *   {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setRetrySleepMillis(int)}
         * </pre>
         */
        private Integer retrySleepMillis = 1000;

        /**
         * http 请求最大重试次数
         * <pre>
         *   {@link cn.binarywang.wx.miniapp.api.impl.BaseWxMaServiceImpl#setMaxRetryTimes(int)}
         * </pre>
         */
        private Integer maxRetryTimes = 5;
    }

}

